package com.wuseguang.springcloud.dao.jdbc;

import com.wuseguang.springcloud.JdbcTemplate.BaseTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;


@Repository
public class PartnerOperationsJdbc extends BaseTemplate {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 添加合作商操作
     *
     * @param id           用户id
     * @param userType     0教师，1学生
     * @param type         0基本信息,1人脸信息
     * @param addOperation 0否,1是
     * @param updOperation 0否,1是
     * @param delOperation 0否,1是
     * @param schoolId     学校id
     * @return
     */
    public Integer addPartnerOperations(Integer id, Integer userType,
                                        Integer type, Integer addOperation,
                                        Integer updOperation, Integer delOperation,
                                        Integer schoolId) {

        try {

            //查询是否有合作商
            String sql = "select partner_id string from partner_school where school_id = ?";
            //合作商id
            String partnerId = queryString(sql, schoolId);

            //判断如果合作商id不为空
            if (!StringUtils.isEmpty(partnerId)) {
                sql = "INSERT INTO  `partner_operations`(`user_id`, `user_type`, `type`, `add`, `update`, `delete`, `partner_id`, `school_id`, `obtain`)" +
                        " VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0)";
                updateByParameter(sql, id, userType, type, addOperation, updOperation, delOperation, partnerId, schoolId);
            }

        } catch (Exception e) {
            logger.error("e", e);
        }

        return 0;
    }
}
